package com.infoyoung.firework.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.extremecomponents.table.limit.Limit;

import com.cidp.system.common.BaseAction;
import com.infoyoung.firework.pojo.FireworkTagPo;
import com.infoyoung.firework.service.IFireworkTagService;
import com.litt.core.common.Constants;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;
import com.litt.core.util.ExtremeTableUtil;

/**
 * <b>标题：</b>烟花管理action实现.
 * <pre><b>描述</b>
 *    烟花管理
 * </pre>
 * 
 * @author caiyuan
 * @since 2008-6-13
 * @version 1.0
 *
 */
public class FireworkTagAction extends BaseAction 
{
	private IFireworkTagService fireworkTagService;
	
	/**
	 * 分页查询
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward search(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
	{
		DynaActionForm dynaActionForm = (DynaActionForm)form;
		FireworkTagPo fireworkTagPo = (FireworkTagPo)dynaActionForm.get("fireworkTagPo");
		
		Limit limit=ExtremeTableUtil.getLimit(request,Constants.DEFAULT_PAGE_SIZE);
		IPageList page = fireworkTagService.listByPage(new PagePoParam(fireworkTagPo, limit.getPage(), limit.getCurrentRowsDisplayed()));
		
		request.setAttribute("resultList", page.getRsList());
		request.setAttribute("totalRows", new Integer(page.getTotalSize()));
		return mapping.findForward("toList");
	}	
	
	/**
	 * 统计查询
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward total(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
	{
		DynaActionForm dynaActionForm = (DynaActionForm)form;
		FireworkTagPo fireworkTagPo = (FireworkTagPo)dynaActionForm.get("fireworkTagPo");
		
		int factoryCount =  fireworkTagService.loadCountByDataType(new Long(1));
		int productCount =  fireworkTagService.loadCountByDataType(new Long(2));
		int storeCount =  fireworkTagService.loadCountByDataType(new Long(3));
		
		List resultList = new ArrayList();
		Map factoryMap = new HashMap();
		factoryMap.put("dataName", "生产商");
		factoryMap.put("dataCount", factoryCount+"");
		resultList.add(factoryMap);
		Map productMap = new HashMap();
		productMap.put("dataName", "产品");
		productMap.put("dataCount", factoryCount+"");
		resultList.add(productMap);
		Map storeMap = new HashMap();
		storeMap.put("dataName", "批发商");
		storeMap.put("dataCount", factoryCount+"");
		resultList.add(storeMap);
		
		request.setAttribute("resultList", resultList);
		return mapping.findForward("toTotal");
	}	
		
	/**
	 * @param fireworkTagService the fireworkTagService to set
	 */
	public void setFireworkTagService(IFireworkTagService fireworkTagService) {
		this.fireworkTagService = fireworkTagService;
	}
}
